{extend name="public:layout" /}
{block name="title"}代码编辑{/block}
{block name="head"}
<script type="text/javascript" src="/public/plugins/in-min.js"></script>
<script type="text/javascript" src="/public/plugins/config/in-config.js"></script>
{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> 代码编辑</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <div class="pull-left">
                    <a href="javascript:;" onclick="back();" class="btn btn-white">返回</a>
                </div>
                <div class="pull-right">
                    <a class="btn btn-white">当前路径：{$filename}</a>
                </div>
                <div class="clearfix"></div>
            </div>
            <form method="post" id="form">
                <input type="hidden" id="filename" value="{$filename}"/>
<textarea id="editCode" name="code">
{$code}
</textarea>
                <button class="btn btn-primary btn-block" id="btnSub" type="button"
                    data-url="{:url('edit')}">保存内容</button>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    In.use('codemirror',function() {
        var editor = CodeMirror.fromTextArea(document.getElementById("editCode"), {
            lineNumbers: true,
            matchBrackets: true,
            mode: "application/x-httpd-php",
            indentUnit: 4,
            indentWithTabs: true,
            styleActiveLine: true
        });
        $('#btnSub').click(function(){
            var url = $(this).data('url');
            $.post(url,{filename:$('#filename').val(),code:editor.getValue()},function(res){
                if(res.code==1){
                    top.layer.msg('修改成功！');
                }else{
                    alert(res.msg);
                }
            });
        });
    });
</script>
{/block}